<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>

    <script th:src="@{/jquery-3.6.0.min.js}"></script>


</head>

<body>
<h1>登录页面</h1>
    用户名:<input type="text" id="userName"><br/>
    密码:<input type="password" id="password"><br/>
    <button id="doLogin">登录</button><br/>
    <span id="errorMsg" style="color: red;display: none" >登录账号密码错误</span>
</body>

<script>

    jQuery(function(){
        $('#password').keydown(function(e){
            if(e.keyCode==13){
                doLogin()
            }
        })
        $('#doLogin').click(function(){
            doLogin()
        })
    })

    function doLogin(){
        var userName = $('#userName').val() //获取id是userName的value值
        var password = $('#password').val() //获取id是userName的value值
        $.ajax({
            url:'/user/doLogin?userName='+userName+'&password='+password,
            type:'get',
            success:function(res){
                if(res=='success'){
                    window.location.href='/home/index'
                }else{
                    $('#errorMsg').css('display','block') //让异常信息显示 提示
                }
            }
        })
    }

</script>

</html>